import {ScrollView} from 'react-native-gesture-handler';
import {Button, WhiteSpace, Flex, List, InputItem, SearchBar, Provider, PickerView, Modal, Carousel} from '@ant-design/react-native';
import React, {Component} from 'react';
import {getParkingArea, getParkingDataList} from '~/api/parking';
import {Alert, Image, StyleSheet, Text, TouchableOpacity, View} from 'react-native';
import CwCard from '~/components/cw-card';

class Carouselcard extends Component {
    constructor(props) {
        super(props);
        this.state = {
            noticelist: this.props.noticelist,
            type: this.props.type || 0,
        };
        this.state.noticelist.forEach((item, index) => {
            if (item.FavoriteState === 1) {
                item.info = '业主' + item.Mobile + '收藏了' + (this.state.type == 1 ? item.ParkingName : '该') + '车位';
            }
            if (item.LogType === 1) {
                item.info = '业主' + item.Mobile + '浏览了' + (this.state.type == 1 ? item.ParkingName : '该') + '车位';
            }
            if (item.Platform === 3) {
                item.info = '业主' + item.Mobile + '正在认购' + (this.state.type == 1 ? item.ParkingName : '该') + '车位';
            }
        });
    }
    render() {
        return (
            <Carousel style={{width: '100%', height: 40}} selectedIndex={0} autoplay={true} infinite={true} autoplayInterval={4000} dots={false}>
                {this.state.noticelist.length > 0 ? (
                    <>
                        <Flex style={styles.noticeView}>
                            <View style={styles.noticeLeft}>
                                <Image style={styles.noticeIcon} source={require('~/assets/community/laba.png')} />
                            </View>
                            <View style={styles.noticeRight}>
                                <Carousel style={styles.noticeList} autoplayInterval={4000} dots={false} vertical autoplay infinite>
                                    {this.state.noticelist.map((item, index) => (
                                        <View style={styles.laba} key={index}>
                                            <Text style={styles.noticeText} numberOfLines={1}>
                                                {item.info}
                                            </Text>
                                        </View>
                                    ))}
                                </Carousel>
                            </View>
                        </Flex>
                        <WhiteSpace />
                    </>
                ) : (
                    <>
                        <Flex style={styles.noticeView}>
                            <View style={styles.noticeLeft}>
                                <Image style={styles.noticeIcon} source={require('~/assets/community/laba.png')} />
                            </View>
                            <View style={styles.noticeRight}>
                                <Text style={{width: '90%', textAlign: 'center'}} numberOfLines={1}>
                                    加载中。。。。。
                                </Text>
                            </View>
                        </Flex>
                        <WhiteSpace />
                    </>
                )}
            </Carousel>
        );
    }
}

export default Carouselcard;
const styles = StyleSheet.create({
    // laba: {
    //     flexDirection: 'row',
    //     justifyContent: 'center',
    //     alignItems: 'center',
    //     width: '100%',
    //     marginTop: 10,
    //     height: 30,
    //     backgroundColor: '#FDEDEC',
    //     borderRadius: 5,
    // },
    noticeView: {
        height: 30,
        backgroundColor: '#FDEDEC',
        borderRadius: 15,
        flexDirection: 'row',
    },
    noticeLeft: {
        marginLeft: 10,
    },
    noticeIcon: {
        width: 26,
        height: 18,
    },
    noticeRight: {
        marginLeft: 10,
        flexGrow: 1,
    },
    noticeList: {
        width: '100%',
        height: 30,
    },
    noticeText: {
        height: '100%',
        fontSize: 11,
        lineHeight: 30,
    },
});
